package cn.wu.jishupeizhi.redisTest;

import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@RunWith(SpringRunner.class) // 确保测试类在 Spring 上下文中运行
public class RedisString {

    @Autowired
    private StringRedisTemplate redisTemplate;

    // 测试数据
    String key = "StringTest";
    String value = "Hello th1111is is String , Redis!";

    @Test
    public void redisStringadd(){
        redisTemplate.opsForValue().set(key,value);
    }

    @Test
    public void redis2() {
        // 获取值并验证
        String retrievedValue = redisTemplate.opsForValue().get(key);
        System.out.println("Retrieved value: " + retrievedValue);
        assertThat(retrievedValue).isEqualTo(value);
    }

    @Test
    public void redis3() {
        // 清理测试数据
        redisTemplate.delete(key);
    }


}
